<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ include file="/views/commons/taglibs.jsp" %>
<input type="hidden" id="discuss_type"  name="discussType" value="${discussType}"/>
<input type="hidden" id="discuss_target_id"  name="discussTargetId" value="${discussTargetId}"/>
<div id="discuss_list_div">
	<div class="social-footer">
		<div class="social-comment">
			暂无评论
		</div>
	</div>
</div>
<div class="social-footer" id="publish_discuss">
	<c:choose>
		<c:when test="${sessionUserInfo!=null && sessionUserInfo.userId !=null}">
			<div class="social-comment">
				<a class="pull-left" href="">
					<img src="<%=path%>/images/default.jpg" alt="image"></a>
				<div class="media-body">
					<form action="javascript:insertDiscuss()" id="discuss_form">
						<c:if test="${discussType==1 || discussType==3 || discussType==4}">
						<div class="zcp_in clearfix">
							<ul>
								<li>
									<div class="radio">
										<input type="radio" name="discussScore" id="discuss_score_1"  value="1" checked="checked">					
										<label for="discuss_score_1">差</label>
									</div>
								</li>
								<li>
									<div class="radio">
										<input type="radio" name="discussScore" id="discuss_score_2" value="2" >					
										<label for="discuss_score_2">一般</label>
									</div>
								</li>
								<li>
									<div class="radio">
										<input type="radio" name="discussScore" id="discuss_score_3" value="3" >					
										<label for="discuss_score_3">好</label>
									</div>
								</li>
							</ul>
						</div>
						</c:if>
						<textarea placeholder="填写评论..." class="form-control" id="discuss_info" name="discussInfo"></textarea>
					
						<div class="mt10">
							<input type="submit" id="discuss_send_btn" class="btn btn-primary" value="发送消息">
						</div>
					</form>
				</div>
			</div>
		</c:when>
		<c:otherwise>
			<div class="social-comment">
				请登录后发表评论
				<a href="<%=path%>/uncheck/login" class="login">登录</a>
			</div>
		</c:otherwise>
	</c:choose>
</div>
<script type="text/javascript">
$(document).ready(function(){
	queryDiscussList(1);
});

function queryDiscussList(pageNo){
	$.ajax({
		url : path + "/uncheck/discuss/list",
		type : "get",
		dataType : "html",
		data : {
			discussType : $("#discuss_type").val(),
			discussTargetId : $("#discuss_target_id").val(),
			discussScore:$("#discuss_score").val(),
			pageNo:pageNo
		},
		success : function(data)
		{
			$("#discuss_list_div").html(data);
		},error:function(){
			layer.msg("服务器网络繁忙",{icon: 2});
		}
	});
}

function queryScoreList(discussScore){
	$("#discuss_score").val(discussScore);
	queryDiscussList(1);
}

function insertDiscuss(){
	$("#discuss_send_btn").addClass("disabled").attr("disabled","disabled").val("发送中");
	
	var insertData=$("#discuss_form").serialize();
	insertData=insertData+"&discussType="+$("#discuss_type").val()+"&discussTargetId="+ $("#discuss_target_id").val();
	$.ajax({
		url : path + "/check/discuss/insert",
		type : "post",
		dataType : "json",
		data : insertData,
		success : function(data)
		{
			if(data.result){
				
				$("#discuss_info").val("");
				layer.msg("发布评论成功",{icon: 1});
				
				$("#discuss_score").val("");
				
				queryDiscussList(1);
				
				$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
			}else{
				layer.msg(data.message,{icon: 2});
				$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
			}
		},error:function(){
			layer.msg("服务器网络繁忙",{icon: 2});
			$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
		}
	});
}
</script>
